package net

import (
	"github.com/shirou/gopsutil/net"
)

// ConnectionsPid pid的网络连接(pid为0代表所有进程的网络连接信息)
func ConnectionsPid(pid int32) ([]net.ConnectionStat, error) {
	if pid <= 0 {
		pid = 0
	}
	connections, err := net.ConnectionsPid("all", pid)

	/*
		type ConnectionStat struct {
			Fd     uint32  `json:"fd"`
			Family uint32  `json:"family"`      //
			Type   uint32  `json:"type"`        // 1: TCP, 2: UDP
			Laddr  Addr    `json:"localaddr"`
			Raddr  Addr    `json:"remoteaddr"`
			Status string  `json:"status"`      // TCP: LISTEN/ESTABLISHED/CLOSE_WAIT  UDP:
			Uids   []int32 `json:"uids"`
			Pid    int32   `json:"pid"`         // process id
		}
	*/

	return connections, err
}
